package com.example.mybatisplusgenerator;

import com.alibaba.fastjson.JSONObject;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

/**
 * @Description TODO
 * @Author fanhailong
 * @Date 2022/5/12 15:56
 */
public class DateUtil {

    public static void main(String[] args) {
        LocalDateTime dateTime=LocalDateTime.parse("2021-01-02 10:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(dateTime);
    }

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     *
     * @param daysAgo 几天前
     * @return
     */
    public static String getTodaySevenTime(int daysAgo) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 7);
        calendar.set(Calendar.MINUTE, 00);
        calendar.set(Calendar.SECOND, 00);
        return sdf.format(calendar.getTime());
    }

    /**
     * 管易同步 获取7天前7点
     *
     * @return
     */
    public static String getSevenAgoSevenTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -7);
        calendar.set(Calendar.HOUR_OF_DAY, 7);
        calendar.set(Calendar.MINUTE, 00);
        calendar.set(Calendar.SECOND, 00);
        return sdf.format(calendar.getTime());
    }

    /**
     * 管易同步 获取15天前7点
     *
     * @return
     */
    public static String getFifteenAgoSevenTime() {
        return null;
    }

}
